window.document.oncontextmenu = function(event) {
  if (event.ctrlKey) return true;
  if (/Android|webOS|BlackBerry/i.test(navigator.userAgent)) return true;
  return popMenu(event);
};
//关闭按钮
// document.addEventListener("click", function(event) {
//   var mymenu = document.getElementById('SAO-back');
//   mymenu.style.display = "none";
// });
//点击元素控制子菜单显隐
function clickItem(){

  //若有点击音乐，则播放点击音乐
  var clickAudio = document.getElementById("SAOClick");
  if (clickAudio) {
    clickAudio.play();
  }
  var clickElement = event.target.parentElement;
  //当点击元素为一级菜单时，若该一级菜单下有二级菜单，显示二级菜单
  if (clickElement.className.indexOf('utils-list-item') > -1){
    console.log('点击的是一级菜单');
    var hasMenulist = clickElement.querySelector('.menu-list');
    if (hasMenulist.className.indexOf('active') < 0) {
      hasMenulist.classList.add('active');
    }
    else{
      hasMenulist.classList.remove('active');
    }
  }
  //当点击元素为二级菜单时，若该二级菜单下有三级菜单，显示三级菜单
  else if (clickElement.className.indexOf('menu-list-item') > -1){
    // console.log('二级菜单');
    var hasChildlist = clickElement.querySelector('.menu-child');
    if (hasChildlist.className.indexOf('active') < 0) {
      hasChildlist.classList.add('active');
      console.log('二级菜单');
    }
    else{
      hasChildlist.classList.remove('active');
    }
  }
}
// //点击菜单内元素播放点击音频
// function clickAudio() {
//   var clickAudio = document.getElementById("SAOClick");
//   if (clickAudio) {
//     clickAudio.play();
//   }
// }

// function Utilsover() {
//   var hasMenulist = event.target.querySelector('.menu-list');
//   if (hasMenulist) {
//     hasMenulist.classList.add('active');
//   }
//
// }
// function Utilsout() {
//   var hasMenulist = event.target.querySelector('.menu-list');
//   if (hasMenulist && hasMenulist.className.indexOf('active') > -1) {
//     setTimeout(function() {
//       hasMenulist.classList.remove('active');
//     }, 500);
//   }
// }
// function Menuover() {
//   var hasMenuchild = event.target.parentNode.querySelector('.menu-child');
//   console.log(hasMenuchild);
//   if (hasMenuchild) {
//     hasMenuchild.classList.add('active');
//   }
// }

function Menuout() {
  var hasMenuchild = event.target.parentNode.querySelector('.menu-child');
  if (hasMenuchild && hasMenuchild.className.indexOf('active') > -1) {
    setTimeout(function() {
      hasMenuchild.classList.remove('active');
    }, 500);
  }
}
function popMenu(event) {
  var audio = document.getElementById("SAOlauncher");
  if (audio) {
    audio.play();
  }
  document.getElementById('SAO-back').style.display = "block";
  var mymenu = document.getElementById('SAO-menu');
  var menuContent = document.getElementById('SAO-menu-content');
  var screenWidth = document.documentElement.clientWidth || document.body.clientWidth;
  var screenHeight = document.documentElement.clientHeight || document.body.clientHeight;
  mymenu.style.left = event.clientX + "px"; // 获取鼠标位置
  mymenu.style.top = event.clientY + "px";
  mymenu.style.display = 'block';
  //根据当前位置决定内容输出
  if (event.clientX * 2 > screenWidth) {
    mymenu.style.left = (event.clientX - menuContent.clientWidth) + "px"; // 获取鼠标位置
  } else {
    mymenu.style.left = event.clientX + "px";
  }
  if (event.clientY * 2 > screenHeight) {
    mymenu.style.top = (event.clientY - menuContent.clientHeight) + "px";
  } else {
    mymenu.style.top = event.clientY + "px";
  }
  return false;
}
